﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Timers;
namespace 慢截图
{
    class RepeatAction
    {
        Action action;
        Timer timer;
        float milliSecond;
        public RepeatAction(float milliSecond,Action action)
        {
            this.action = action;
            timer = new Timer();
            this.milliSecond = milliSecond;
        }
        public void Start() 
        {
            timer.Interval = milliSecond;
            timer.Elapsed += fun;
            timer.Start();
        }

        private void fun(object sender, ElapsedEventArgs e)
        {
            action();
        }

        public void Stop() 
        {
            timer.Elapsed -= fun;
            timer.Stop();
            timer.Dispose();
        }
    }
}
